package com.dps.recommend.layer.rank;

import com.dps.recommend.ann.LayerAnn;
import com.dps.recommend.beans.DpsRequest;
import com.dps.recommend.beans.ProcessInterface;
import com.dps.recommend.beans.RecItemDps;
import com.dps.recommend.enums.LayerEnum;
import com.dps.recommend.utils.DpsBaseService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * 强制类型(type字段)轮询、最大化保留顺序、类型天然散列
 */
@Service
@LayerAnn(layer = LayerEnum.RANK)
class DpsTypeDisRank extends DpsBaseService implements ProcessInterface {

    @Override
    public <R extends RecItemDps> List doProcess(DpsRequest dpsRequest, List<R> list) {
        String pageSizeStr = (String) dpsRequest.getRoad().getProperties().getOrDefault("pageSize", String.valueOf(dpsRequest.getRequest().getPageSize()));
        int pageSzie = Integer.valueOf(pageSizeStr);
        if (CollectionUtils.isEmpty(list)) {
            return list;
        }
        return typeDisPer(dpsRequest, list, pageSzie > list.size() ? list.size() : pageSzie);
    }


}
